
package IA;

/**
 *
 * @author Jeremy
 */

import java.util.*;
import iterators.*;
public class ServiceCollection {
    private ArrayList<Service> services;
    private ArrayList<Service> CompletedServices; //to keep track of data
    public ServiceCollection() {
        services = new ArrayList<Service>();
        CompletedServices = new ArrayList<Service>();
    }
    
    public Service AddService(int NumCustomers, int TableID, int ServerID, int EatingTime) {
        services.add(new Service(NumCustomers, TableID, ServerID, EatingTime));
        return services.get(services.size() - 1);
    }
    
    public void ServiceFinished(Service s) {
        CompletedServices.add(s);
        services.remove(s);
    }
    
    public Service getLastAddedService() {
        return services.get(services.size() - 1);
    }
    
    public Service ServiceByTable(int TableIndex) {
        for(int i = 0; i < services.size(); i++) {
            if(services.get(i).getTableID() == TableIndex) return services.get(i);
        }
        return null;
    }
    
    public Iterator<Service> getServiceIterator() {
        return services.iterator();
    }
    
    public Iterator<Service> getCompletedServiceIterator() {
        return new ReverseCompletedServiceIterator(CompletedServices);
    }
    
    public int getNumServices() {
        return services.size();
    }
    
    public int getNumCompletedServices() {
        return CompletedServices.size();
    }
}
